package com.example.day13;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;
import java.util.Map;

public class MyAdapter extends BaseAdapter {
    Context context;
    List<Map<String,Object>> list1;
    public MyAdapter(Context context, List<Map<String,Object>> list1){
        this.context=context;
        this.list1=list1;
    }
    @Override
    public int getCount() {
        return list1.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View view =View.inflate(context,R.layout.test_item,null);
        TextView textView = view.findViewById(R.id.textView);
        TextView textView1 = view.findViewById(R.id.textView2);
        ImageView image= view.findViewById(R.id.imageView);
        Map<String,Object> map= list1.get(position);
        textView.setText(map.get("title").toString());
        textView1.setText(map.get("view_num").toString());
        if(map.get("img_url")!=null){
            image.setImageBitmap((Bitmap)map.get("img_url"));
        }
        return view;
    }
}
